define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pt/white_black/index' + location.search,
                    /*
                    add_url: 'pt/white_black/add',
                    edit_url: 'pt/white_black/edit',
                    del_url: 'pt/white_black/del',
                    */
                    multi_url: 'pt/white_black/multi',
                    import_url: 'pt/white_black/import',
                    table: 'pt_whiteblack_list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), visible: false, operate: false},
                        {field: 'person.user_name', title: __('人员姓名'), operate: false},
                        {field: 'person.sex', title: __('性别'), searchList: {"0":__('保密'),"1":__('男'),"2":__('女')}, operate: false,
                          formatter: function(value, row, index) {
                            if (value == '0') {
                                return '保密';
                            }
                            if (value == '1') {
                                return '男';
                            }
                            if (value == '2') {
                                return '女';
                            }
                            return '未知';
                          }
                        },
                        {field: 'person.phone', title: __('联系电话'), operate: false},
                        {field: 'person.user_type', title: __('人员类别'),searchList: {"self":__('自招兼职'),"intern":__('实习生'),"labor":__('劳务公司')}, operate: false,
                          formatter: function(value, row, index) {
                            if (value == 'self') {
                                return '自招兼职';
                            }
                            if (value == 'intern') {
                                return '实习生';
                            }
                            if (value == 'labor') {
                                return '劳务公司';
                            }
                            return '未知';
                          }
                        },
                        {field: 'person.labor.name', title: __('劳务公司'), operate: false},

                        {field: 'white_black', title: __('White_black'), searchList: {"white":__('White_black white'),"black":__('White_black black')}, formatter: Table.api.formatter.normal},
                        {field: 'note', title: __('Note'), operate: 'LIKE'},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('最后调整时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
